﻿namespace EFS.RC.CC.Config.Scheduler
{
	public class Week : EFS.Common.Serialization.ISerializable, System.Collections.Generic.IEnumerable<EFS.RC.CC.Config.Scheduler.Day>
	{
		/// <summary>
		/// Time intervals
		/// </summary>
		private EFS.RC.CC.Config.Scheduler.Day[] days = new EFS.RC.CC.Config.Scheduler.Day[0];

		/// <summary>
		/// Constructor
		/// </summary>
		public Week()
		{
		}

		/// Serialize
		public void Serialize(EFS.Common.Serialization.XmlWriter xmlWriter)
		{
			// write
			xmlWriter.Write<EFS.RC.CC.Config.Scheduler.Day>("Days", "Day", days);
		}

		/// Deserialize
		public void Deserialize(EFS.Common.Serialization.XmlReader xmlReader)
		{
			// read
			xmlReader.Read<EFS.RC.CC.Config.Scheduler.Day>("Days", "Day", ref days);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="dayNumber"></param>
		/// <returns></returns>
		public EFS.RC.CC.Config.Scheduler.Day Day(System.DayOfWeek dayOfWeek)
		{
			// get day
			foreach(Day day in this)
			{
				if (day.DayOfWeek == dayOfWeek)
				{
					return day;
				}
			}

			// not in
			return null;
		}

		/// <summary>
		/// Get enumerator
		/// </summary>
		/// <returns></returns>
		public System.Collections.IEnumerator GetEnumerator()
		{
			return days.GetEnumerator();
		}

		/// <summary>
		/// Get enumerator
		/// </summary>
		/// <returns></returns>
		System.Collections.Generic.IEnumerator<EFS.RC.CC.Config.Scheduler.Day> System.Collections.Generic.IEnumerable<EFS.RC.CC.Config.Scheduler.Day>.GetEnumerator()
		{
			return (System.Collections.Generic.IEnumerator<EFS.RC.CC.Config.Scheduler.Day>)days.GetEnumerator();
		}
	}
}